package com.mufeng.libs.net

import kotlinx.coroutines.flow.Flow


class RequestAction<T> {

    // 开始请求
    var start: (() -> Unit)? = null
        private set

    // 发起请求
    var request: (suspend () -> Flow<ResponseBean<T>>)? = null
        private set

    // 请求成功
    var success: ((ResponseBean<T>) -> Unit)? = null
        private set

    // 请求失败
    var error: ((code: String, msg: String) -> Unit)? = null
        private set

    fun request(block: suspend () -> Flow<ResponseBean<T>>) {
        request = block
    }

    fun start(block: () -> Unit) {
        start = block
    }

    fun success(block: (ResponseBean<T>) -> Unit) {
        success = block
    }

    fun error(block: (code: String, msg: String) -> Unit) {
        error = block
    }

}
